package com.bootcamp.javase2.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;

/**
 * @program: IOCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-09 20:00
 **/

public class PrintFile {
    public static void print(String sfile) throws IOException {
        File file = new File(sfile);
        if (!file.exists()){
            System.out.println("file not exist!");
            return;
        }
        FileInputStream in = new FileInputStream(file);
        System.out.println("name: "+sfile);
        byte[] bytes = new byte[10];
        int readCount;
        while ((readCount=in.read(bytes))!=-1){
            printByte(bytes);
        }
        in.close();
    }

    private static void printByte(byte[] bytes) {
        for (byte b : bytes) {
            System.out.print((char)b+" ");
        }
        System.out.println();
    }
}
